using System.Xml;
using System;

namespace ValidationFramework.Configuration.Xml
{
	public class RuleConfigReader : IRuleConfigReader
	{
		private ISpecificationXmlParser _validatorParser;

		public RuleConfigReader(ISpecificationXmlParser parser)
		{
			_validatorParser = parser;
		}
		/// <inheritdoc />
		public Rule ReadConfig(RuleData ruleData, RuleContext context)
		{
			Guard.ArgumentNotNull(ruleData, "ruleData");

			return new Rule(_validatorParser.GetSpecification(ruleData.ValidatorXmlElement, context))
			{
				ErrorMessage = ruleData.ErrorMessage,
				RuleSet = ruleData.RuleSet,
				UseErrorMessageProvider = ruleData.UseErrorMessageProvider,
			};
		}
	}
}
